package com.blink.optimize.apis.string;

import org.junit.jupiter.api.Test;

/**
 * <Description> </Description>
 * <ClassName> TestBuildString</ClassName>
 *
 * @Author liuxianzhao
 * @Date 2018年01月08日 15:31
 */
public class TestBuildString {
    @Test
    public void testStringConcat() {
        long start = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < 10_000; i++) {
            str = str.concat(String.valueOf(i));
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    @Test
    public void testStringBuffer() {
        long start = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 10_000; i++) {
            sb.append(i);
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    @Test
    public void testStringBuilder() {
        long start = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 10_000; i++) {
            sb.append(i);
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    @Test
    public void testStringPlus() {
        long start = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < 10_000; i++) {
            str = str + i;
        }
        System.out.println(System.currentTimeMillis() - start);
    }
}
